package com.lovo.roomProject.room.service.impl;

import com.lovo.roomProject.pojo.CutPageBean;
import com.lovo.roomProject.pojo.RoomDO;
import com.lovo.roomProject.pojo.RoomSetDO;
import com.lovo.roomProject.room.dao.RoomDAO;
import com.lovo.roomProject.room.dao.RoomSetDAO;
import com.lovo.roomProject.room.dao.impl.RoomDAOImpl;
import com.lovo.roomProject.room.dao.impl.RoomSetDAOImpl;
import com.lovo.roomProject.room.service.RooSetService;

public class RoomSetServiceImpl implements RooSetService {
    RoomSetDAO roomSetDAO = new RoomSetDAOImpl();
    RoomDAO roomDAO = new RoomDAOImpl();

    @Override
    public CutPageBean listRoomsSetByPage(int current, int roomID) {
        return roomSetDAO.listRoomsSetByPage(current, roomID,null);
    }

    @Override
    public RoomSetDO getRoomSetById(int id) {
        return roomSetDAO.getRoomSetById(id);
    }

    @Override
    public void insert(RoomSetDO roomSetDO) {
        roomSetDAO.insert(roomSetDO);
        //更新所在房间状态
        RoomDO roomDO = roomDAO.getRoomById(roomSetDO.getRoomId());
        roomDO.setStatus("设施损坏");
        roomDAO.update(roomDO);
    }


    @Override
    public void update(RoomSetDO roomSetDO) {
        roomSetDAO.update(roomSetDO);
        //得到当所在房间的所有未处理记录
        CutPageBean cutPageBean = roomSetDAO.listRoomsSetByPage(1,roomSetDO.getRoomId(),"未处理");
        if (cutPageBean.getCount()==0){
            //更新所在房间状态
            RoomDO roomDO = roomDAO.getRoomById(roomSetDO.getRoomId());
            roomDO.setStatus("正常");
            roomDAO.update(roomDO);
        }

    }

}
